package org.emet.entity.biz;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.emet.help.CGResource;
import org.emet.jee.console.entity.BaseEntity;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

@Entity
@Table(name = "T_CHARGE_REC")
public class ChargeRecord extends BaseEntity {
	private Registration registration;

	//收费日期
	@CGResource("收费日期")
	private Date chargeDate;
	//操作员
	@CGResource("操作员")
	private String operator;

	//总费用
	@CGResource("总费用")
	private double totalFee;
	//应付费用
	@CGResource("应付费用")
	private double shouldPaidTotalFee;
	//已付总费用
	@CGResource("已付总费用")
	private double paidFee;

	private List<ChargeItem> items = new ArrayList<ChargeItem>();

	@ManyToOne(targetEntity = Registration.class)
	@Cascade({ org.hibernate.annotations.CascadeType.SAVE_UPDATE })
	@JoinColumn(name = "reg_id")
	public Registration getRegistration() {
		return registration;
	}

	public void setRegistration(Registration registration) {
		this.registration = registration;
	}

	public double getTotalFee() {
		return totalFee;
	}

	public void setTotalFee(double totalFee) {
		this.totalFee = totalFee;
	}

	public double getShouldPaidTotalFee() {
		return shouldPaidTotalFee;
	}

	public void setShouldPaidTotalFee(double shouldPaidTotalFee) {
		this.shouldPaidTotalFee = shouldPaidTotalFee;
	}

	public double getPaidFee() {
		return paidFee;
	}

	public void setPaidFee(double paidFee) {
		this.paidFee = paidFee;
	}

	@OneToMany(mappedBy = "chargeRecord")
	@Cascade({ org.hibernate.annotations.CascadeType.ALL })
	@JoinColumn(name = "rec_id")
	@OnDelete(action = OnDeleteAction.CASCADE)
	@OrderBy("id asc")
	public List<ChargeItem> getItems() {
		return items;
	}

	public void setItems(List<ChargeItem> items) {
		this.items = items;
	}

	public Date getChargeDate() {
		return chargeDate;
	}

	public void setChargeDate(Date chargeDate) {
		this.chargeDate = chargeDate;
	}

	public String getOperator() {
		return operator;
	}

	public void setOperator(String operator) {
		this.operator = operator;
	}

	@Override
	public String toString() {
		return ToStringBuilder.reflectionToString(this);
	}

}
